package com.xiaoyu.lingdian.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.xiaoyu.lingdian.service.CoreAddressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.xiaoyu.lingdian.core.mybatis.dao.MyBatisDAO;
import com.xiaoyu.lingdian.core.mybatis.page.Page;
import com.xiaoyu.lingdian.core.mybatis.page.PageRequest;
import com.xiaoyu.lingdian.entity.CoreAddress;

@Service("coreAddressService")
public class CoreAddressServiceImpl implements CoreAddressService {

	@Autowired
	private MyBatisDAO myBatisDAO;

	@Override
	public boolean insertCoreAddress(CoreAddress coreAddress) {
		myBatisDAO.insert(coreAddress);
		return true;
	}

	@Override
	public boolean updateCoreAddress(CoreAddress coreAddress) {
		myBatisDAO.update(coreAddress);
		return true;
	}

	@Override
	public boolean deleteCoreAddress(CoreAddress coreAddress) {
		myBatisDAO.delete(coreAddress);
		return true;
	}

	@Override
	public CoreAddress getCoreAddress(CoreAddress coreAddress) {
		return (CoreAddress) myBatisDAO.findForObject(coreAddress);
	}

	private static final String FIND_CORE_ADDRESS_BY_CND = "findCoreAddressByCnd";
	private static final String DELETE_CORE_ADDRESS_BY_CND = "deleteCoreAddressByCnd";
	
	@SuppressWarnings("unchecked")
	@Override
	public Page<CoreAddress> findCoreAddressByCnd(String crarsUser,
			String crarsName, int pageNum, int pageSize) {
		Map<String, Object> hashMap = new HashMap<String, Object>();
		hashMap.put("crarsUser", crarsUser);
		hashMap.put("crarsName", crarsName);
		return myBatisDAO.findForPage(FIND_CORE_ADDRESS_BY_CND, new PageRequest(pageNum, pageSize, hashMap));
	}

	@Override
	public boolean deleteCoreAddressByCnd(List<String> list) {
		Map<String, Object> hashMap = new HashMap<String, Object>();
		hashMap.put("list", list);
		myBatisDAO.delete(DELETE_CORE_ADDRESS_BY_CND, hashMap);
		return true;
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<CoreAddress> findCoreAddressByMy(String crarsUser) {
		Map<String, Object> hashMap = new HashMap<String, Object>();
		hashMap.put("crarsUser", crarsUser);
		return myBatisDAO.findForList(FIND_CORE_ADDRESS_BY_CND, hashMap);
	}

	
}